/*
 *  HASFLAVR.h
 *  TubeTruck
 *
 *  Created by Aeturnum on 6/6/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#pragma once

#include <vector>
#include <assert.h>
#include <exception>

#include "TubeTruckTypes.h"
#include "serialization.h"
#include "unserialization.h" 
#include "smartalloc_wrap.h"
#include "Signable.h"
#include "Signiture.h"
#include "Encryptable.h"
#include "RSA.h"
#include "util.h"

namespace TTP {
   class HASFLAVR : public Packet, public Crypt::Signable, public Crypt::Encryptable  {
   protected:
      byte mFlags;
      std::vector<byte> mBlowfishIv;
      
      void fillEncryptedSection();
      
   public:
      enum {HASFLAVR_yes = 0x01, HASFLAVR_no = 0x02, HASFLAVR_votesNeeded = 0x04};
      
      HASFLAVR();
      HASFLAVR(id_hash);
      HASFLAVR(id_hash,std::vector<byte>&,byte);
      ~HASFLAVR();
      
      // accessors
      byte getFlags() const;
      bool getFlag(byte flag) const;
      std::vector<byte> getBlowfishIv();
      
      // modifiers
      void setFlags(byte flags);
      void setFlag(byte flag);
      void setBlowfishIv(std::vector<byte>&);
      
      //idHash
      void  setSourceIdHash(id_hash);
      id_hash getSourceIdHash() const;
      
      // inherited
      void fromVec(std::vector<byte>::const_iterator &vit, std::vector<byte>::const_iterator &end);
      void toVec(std::vector<byte> &vec) const;
      
      void setEncryptedData(std::vector<byte>&);
      void setPlainText(std::vector<byte>&);
      std::vector<byte> getEncryptedSection();
      
      std::vector<byte> getUnsignedData() const;
   };
}
